package cn.huixh.blindbox.pojo.vo;

import cn.huixh.blindbox.pojo.po.Note;
import cn.hutool.core.date.DateUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author huixh
 * @version 1.0
 * @date 2022/5/13 11:41
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class NoteVO {
    /**
     * 纸条id
     */
    private String noteId;
    /**
     * 简单介绍
     */
    private String noteContent;

    private String vx;
    /**
     * 图片 id 列表
     */
    private List< String > noteImg;

    private String datetime;

    public static NoteVO of(Note note) {
        List< String > stringList = new ArrayList<>(note.getFiles().size());

        note.getFiles().forEach(file -> stringList.add(file.getId()));
        String format = DateUtil.format(note.getCreateTime(), "yyyy-MM-dd");
        return NoteVO.builder().noteImg(stringList).noteContent(note.getContent()).noteId(note.getId()).vx(note.getWechat()).datetime(format).build();

    }
}
